package com.example.smartcity_poverty.ui.AllService.PetHospital.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.smartcity_poverty.App.Companion.getToken
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.Repository.api
import com.example.smartcity_poverty.logic.Repository.coroutine
import com.example.smartcity_poverty.logic.ServiceBean.PetHospitalBean.JsThisAllModel
import com.example.smartcity_poverty.logic.util.Util.show
import com.example.smartcity_poverty.ui.AllService.PetHospital.adapter.JsThisAdapter
import kotlinx.android.synthetic.main.activity_js_this_add.*

/**
 * 找医生
 */
class JsThisAddActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_js_this_add)
        title = "找医生"

        // 获取数据
        val arrayList = ArrayList<JsThisAllModel.RowsBean>()
        coroutine {
            api.getJsThisAll(getToken()).apply {
                if (this.code == 200) {
                    arrayList.addAll(this.rows!!)
                    runOnUiThread {
                        jsThisAddRv.apply {
                            this.isNestedScrollingEnabled = false
                            this.adapter = JsThisAdapter(arrayList, R.layout.re_js_this_all_list)
                            this.layoutManager = LinearLayoutManager(context)
                            this.adapter?.notifyItemChanged(arrayList.size)
                        }
                    }
                } else runOnUiThread { this.msg?.show() }
            }
        }

    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}